<template>
  <div class="re-list-page">
    <el-table
      :data="reListData"
      :empty-text="emptyText"
      stripe
      class="re-list">
      <el-table-column
        type="index"
        label="序号"
        width="70">
      </el-table-column>
      <el-table-column
        prop="pn"
        label="公开/公告号"
        width="200">
      </el-table-column>
      <el-table-column
        prop="ttl"
        label="专利名称">
      </el-table-column>
      <el-table-column
        prop="an"
        label="申请人">
      </el-table-column>
      <el-table-column
        prop="ipcm"
        label="主分类号"
        width="200">
      </el-table-column>
      <el-table-column
        prop="score"
        label="相关度"
        width="200">
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div v-show="totalRow>0" class="pagination">
      <span>每页显示条数</span>
      <el-select
        v-model="pageSize"
        class="page-size"
        @change="handleCurrentChange(1)">
        <el-option
          v-for="item in page"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        small
        :page-size="pageSize"
        layout="prev, pager, next, jumper"
        :total="totalRow">
      </el-pagination>
      <span class="btn go">确定</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    publicInfo: {
      type: Object
    }
  },
  data() {
    return {
      reListData: [],
      allList: [],
      totalRow: 0,
      currentPage: 1,
      pageSize: 10,
      page: [
        {
          value: 5,
          label: '5'
        },
        {
          value: 10,
          label: '10'
        }, {
          value: 20,
          label: '20'
        }, {
          value: 50,
          label: '50'
        }, {
          value: 100,
          label: '100'
        }
      ],
      emptyText: '数据加载中...'
    }
  },
  methods: {
    init() {
      this.emptyText = '数据加载中...'
      this.$post(this.$Url.search.commonSearch, {
        dbid:'patent',
        eSearch: 'R/' + this.publicInfo.pn   
      }).then(res => {
        let data = res.data
        if (data) {
          let result = data.result || []
          if (result.length <= 0) {
            this.emptyText = '暂无数据'
            return
          }
          this.totalRow = data.total
          let list = []
          for (let i in result) {
            let v = result[i]
            let obj = {
              pn: v.pn || '--', // 公开/公告号
              ttl: v.ttl, // 专利名称
              an: v.an && v.an.join('; ') || '--', // 申请人
              ipcm: v.ipcm || '--', // 主分类号
              score: v.score && (Number(v.score).toFixed(2) + '%') || '--', // 相关度
            }
            list.push(obj)
          }
          this.allList = list
          
          this.reListData = this.allList.slice(this.pageSize * (this.currentPage - 1), this.pageSize * this.currentPage)
        } else {
          this.emptyText = '暂无数据'
        }
        
      }).catch(err => {
        this.emptyText = '暂无数据'
      })
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.reListData = this.allList.slice(this.pageSize * (this.currentPage - 1), this.pageSize * this.currentPage)
    },
  },
  mounted() {
    this.init()
  }
}
</script>

<style lang="scss" scoped>
.re-list-page {
  width: 100%;
  .pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 64px;
    font-size: 12px;
    background-color: #fff;
    .page-size {
      width: 70px;
      margin: 0 10px 0 5px;
    }
    .go {
      padding: 3px 5px;
      border-radius: 3px;
      margin-left: 4px;
      color: #fff;
      background-color: $color141;
    }
  }
}
</style>